﻿using System;
using Microsoft.Extensions.DependencyInjection;
namespace Odyssey.xUnit.Console
{
    using Application;

    class Startup : IStartup
    {
        public void Configure(IServiceProvider serviceProvider)
        {
            var appliactionLifetime = serviceProvider.GetRequiredService<IApplicationLifetime>();

            appliactionLifetime.ApplicationStarted.Register(() =>
            {
                System.Console.WriteLine("Application Start...");
            });
            appliactionLifetime.ApplicationStopped.Register(() =>
            {
                System.Console.WriteLine("Application Stop...");
            });

            serviceProvider.GetRequiredService<Program>().Doing();
        }

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<Program>();
            return services.BuildServiceProvider();
        }
    }

    class Program
    {
        public void Doing()
        {
            System.Console.WriteLine("Hello Odyssey");
        }

        static void Main(string[] args)
        {
            new HostBuilder()
                .UseStartup<Startup>()
                .Build()
                .Start();
        }
    }
}
